import moment from 'moment';

const reg =
  /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;

export const isUrl = (path: string): boolean => reg.test(path);
type TimeVal = React.ReactNode | Date | number | string;
export const handleTime = (time?: TimeVal, format: string = 'YYYY-MM-DD HH:mm:ss') => {
  if (typeof time === 'string') return moment(time).format(format);
  return moment(time?.toString()).format(format);
};

// 数字、26个英文字母或下划线组成的字符串
export const passwordReg = /^\\w+$/;

export const urlReg = /^(http|https):\/\//;

// 包含大小写字母和数字的组合，不能使用特殊字符，长度在8-10之间
export const passwordReg2 = /^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$/;

// 汉字
export const zhReg = new RegExp('[\\u4E00-\\u9FFF]+', 'g');

// 由数字、26个英文字母或者下划线组成的长度小于50的字符串:
export const standardReg = /^[0-9a-zA-Z_]{1,50}$/;

// 必须由字母和数字组成
export const letterAndNumberReg = /[0-9]+[a-zA-Z]+[0-9a-zA-Z]*|[a-zA-Z]+[0-9]+[0-9a-zA-Z]*/;

export const ipAddrReg =
  /((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))/;
